/**
 * Created by yangjingbo on 17-5-7.
 */

angular.module('companyRegister',[])
    .component('companyRegister',{
    templateUrl:'component/base/companyRegister/companyRegister.html',
    controller: ['$rootScope','$scope','Api','Enum','$state','CompanyModel','Check','Prompt',
        function ($rootScope,$scope,Api,Enum,$state,CompanyModel,Check,Prompt) {
        $scope.number=0;
        $scope.regChangeShow=regChangeShow;
        $scope.value=Prompt;
        $scope.checkUsername=checkUsername;

        getCommunities();
        getCitys();
        setupCompanyModel();

         function setupCompanyModel() {
            $rootScope.$watch('RootCompanyInfo', function (newCompany) {
                if (newCompany) {
                    // console.log(JSON.stringify(new CompanyModel(newCompany)))
                    $scope.companyModel = new CompanyModel(newCompany);
                }
            })
        }

        function getCitys() {
            Api.getChinaCitysJson(function (result) {

                    $scope.citys = result;

            });
        }

        function checkUsername(value) {
            var judge =Check.username(value);
            if (!judge){
                $scope.number='12';
            }
        }
        function regChangeShow() {
            $scope.number=true;
        }
        function getCommunities() {
            Api.getCommunityList(function (result) {
                $scope.cummunityList = result.data;
            })
        }

    }]
});

